package com.shareit.ocr.domain.template;

import com.shareit.ocr.domain.SimulatorRequestInfo;
import com.shareit.ocr.enums.ResultEnum;
import com.shareit.ocr.exception.SimulatorException;
import com.shareit.ocr.util.InvoiceQueryUtil;

/**  
* 发票数据模版创建工厂   
*  
* @author geai
* @date 2018年1月19日  新建  
*/
public class InvoiceDataTemplateFactory {
	
	
	public static InvoiceDataTemplate createInstance_04(){

		InvoiceDataHeaderTemplate header;
		InvoiceDataItemTemplate item;
		
		header = new InvoiceData04HeaderTemplate();
		item = new InvoiceData04ItemTemplate();
		
		InvoiceDataTemplate template = new InvoiceDataTemplate(header, item);
		return template;
	}

	
	public static InvoiceDataTemplate createInstance(SimulatorRequestInfo sri) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
		
		InvoiceDataTemplate dataTemplate;
		InvoiceDataHeaderTemplate header;
		InvoiceDataItemTemplate item;
		
		String type = InvoiceQueryUtil.getInvoiceType(sri.getFpdm());
		if ("99".equals(type)) {
			throw new SimulatorException(ResultEnum.INVOICE_FPDM_ERROR);
		}
		
		String headerClassname = "com.shareit.ocr.domain.template.InvoiceData" + type + "HeaderTemplate";
		header = (InvoiceDataHeaderTemplate)Class.forName(headerClassname).newInstance();
		header.initalFields(sri);
		String itemClassname = "com.shareit.ocr.domain.template.InvoiceData" + type + "ItemTemplate";
		item = (InvoiceDataItemTemplate)Class.forName(itemClassname).newInstance();
		dataTemplate = new InvoiceDataTemplate(header, item);
		return dataTemplate;
	}
}
